package jj.rmirm.gui;

import javax.swing.JList;

public class ObjListDisplay {
	
	public ObjListDisplay(JList objList) {
		this.objList = objList;
	}
	
	/**
	 * Updates list of registered objects inside JList
	 * @param newObjList new list of registered objects
	 */
	public void updateResult(String newObjList[]) {
		if(this.allowUpdate) {
			this.objList.setListData(newObjList);
			this.objList.setSelectedIndex(this.lastSelectedIndex);
		}
	}//updateResult(String newObjList[])
	
	/**
	 * Determines that list of objects can be refreshed or not
	 * @param can If true - list can be refreshed
	 */
	public void canUpdate(boolean can) {
		this.allowUpdate = can;
	}
	
	/**
	 * 
	 * @param idx Index of last selected item in objectList
	 */
	public void setSelectedIdx(int idx) {
		this.lastSelectedIndex = idx;
	}
	
	public void clear() {
		String tmp[] = new String[0];
		this.objList.setListData(tmp);
	}

	private JList objList;
	private boolean allowUpdate = true;
	private int lastSelectedIndex = 0;
}
